let hall_yh_controller = {
    // 查询所有的电影信息初始化热播电影
    findHallAll: function (pageNum, pageSize) {
        axios({
            url: "/admin/cinema/hall/all",
            method: "POST",
            data: {
                pageNum: pageNum,
                pageSize: pageSize,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.hallList = value.data.data.list;
                vueapp.page = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的影片类型
    findHallTypeAll: function () {
        axios({
            url: "/admin/cinema/hall/type/all",
            method: "GET",
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.hallTypeList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的影院信息
    findCinemaAll: function () {
        axios({
            url: "/admin/cinema/all",
            method: "GET",
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.cinemaList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 根据ID查询影厅信息
    findHallById: function (hallId) {
        axios({
            url: "/admin/cinema/hall/detail/id",
            method: "GET",
            params: {
                hallId: hallId,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.hallDetail.hall = value.data.data.hall;
                vueapp.hallDetail.hallType = value.data.data.hallType;
                var layoutList = value.data.data.layout;
                if (layoutList != null) {
                    vueapp.hallDetail.layoutList = layoutList;
                }else {
                    vueapp.hallDetail.layoutList = [];
                }
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 添加影厅信息
    addHall: function () {
        // 生成布局信息.如果存在旧数据就清空
        if (this.hall.layout.length>0) {
            this.hall.layout = [];
        }
        this.calculateLayout();
        var layout = this.hall.layout;
        axios({
            url: "/admin/cinema/add/hall",
            method: "POST",
            data: {
                hallName: this.hall.hallName,
                hallTypeId: this.hall.hallTypeId,
                cinemaId: this.hall.cinemaId,
                hallCapacity: this.hall.hallCapacity,
                layout: layout,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '添加成功！',
                    type: 'success'
                });
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 修改影厅信息
    updateHall: function () {
        var hallTypeId = this.hallDetail.hall.hallTypeId;
        if (hallTypeId==null) {
            hallTypeId = 0;
        }
        var layoutList = this.hallDetail.layoutList;
        var hallId = this.hallDetail.hall.hallId;
        if (layoutList.length>0) {
            axios({
                url: "/admin/cinema/update/hall",
                method: "POST",
                data: {
                    hallId: hallId,
                    hallName: this.hallDetail.hall.hallName,
                    hallTypeId: hallTypeId,
                    cinemaId: this.hallDetail.hall.cinemaId,
                    hallCapacity: this.hallDetail.hall.hallCapacity,
                }
            }).then(function (value) {
                if (value.data.code == 200) {
                    vueapp.$message({
                        message: '修改成功！',
                        type: 'success'
                    });
                } else {
                    vueapp.$alert(value.data.msg, '提示', {
                        confirmButtonText: '确定',
                    });
                }
                // 更新展示的影厅数据
                vueapp.findHallById(hallId);
            })
        }else {
            // 生成布局信息.如果存在旧数据就清空
            if (this.hall.layout.length>0) {
                this.hall.layout = [];
            }
            this.calculateLayout();
            var layout = this.hall.layout;
            axios({
                url: "/admin/cinema/update/hall",
                method: "POST",
                data: {
                    hallId: hallId,
                    hallName: this.hallDetail.hall.hallName,
                    hallTypeId: hallTypeId,
                    cinemaId: this.hallDetail.hall.cinemaId,
                    hallCapacity: this.hall.hallCapacity,
                    layout: layout,
                }
            }).then(function (value) {
                if (value.data.code == 200) {
                    vueapp.$message({
                        message: '修改成功！',
                        type: 'success'
                    });
                } else {
                    vueapp.$alert(value.data.msg, '提示', {
                        confirmButtonText: '确定',
                    });
                }
                // 更新展示的影厅数据
                vueapp.findHallById(hallId);
            })
        }
    },

    // 根据影厅移除所有关联的布局信息
    removeLayoutByHall: function (hallId) {
        axios({
            url: "/admin/cinema/del/layout",
            method: "GET",
            params: {
                hallId: hallId,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '删除成功！',
                    type: 'success'
                });
                // 更新展示的影厅数据
                vueapp.findHallById(hallId);
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    }
}